<?php

/**
 * This is the model class for table "zy_award_sms".
 *
 * The followings are the available columns in table 'zy_award_sms':
	 * @property integer $awardSms_id
	 * @property string $awardSms_title
	 * @property string $awardSms_content
	 * @property string $message_en
	 * @property string $message_zh_cn
	 * @property integer $is_delete
	 * @property string $remark
	 * @property string $create_time
	 * @property string $create_user
	 * @property string $update_time
	 * @property string $update_user
 */
class EventAwardSms extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AwardSms the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_event_award_sms';
	}
	public function primaryKey()
	{
		return 'awardSms_id';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('is_delete', 'numerical', 'integerOnly'=>true),
			array('awardSms_title, message_en, message_cn, remark, create_user, update_user', 'length', 'max'=>255),
			array('create_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('awardSms_id,event_id, awardSms_title, message_en, message_cn, is_delete, remark, create_time, create_user, update_time, update_user,award_remark', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'awardSms_id' =>Yii::t("EventAwardSms","Award Sms ID"),
			'event_id' =>Yii::t("EventAwardSms","Award Sms ID"),
			'awardSms_title' =>Yii::t("EventAwardSms","Award Sms Title"),
			'message_en' =>Yii::t("EventAwardSms","Message En"),
			'message_cn' =>Yii::t("EventAwardSms","Message Cn"),
			'is_delete' =>Yii::t("EventAwardSms","Is Delete"),
			'remark' =>Yii::t("EventAwardSms","Remark"),
			'create_time' =>Yii::t("EventAwardSms","Create Time"),
			'create_user' =>Yii::t("EventAwardSms","Create User"),
			'update_time' =>Yii::t("EventAwardSms","Update Time"),
			'update_user' =>Yii::t("EventAwardSms","Update User"),
			'award_remark' =>Yii::t("EventAwardSms","Award Remark"),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('awardSms_id',$this->awardSms_id);
		$criteria->compare('event_id',$this->event_id);
		$criteria->compare('awardSms_title',$this->awardSms_title,true);
		$criteria->compare('message_en',$this->message_en,true);
		$criteria->compare('message_cn',$this->message_cn,true);
		$criteria->compare('is_delete',$this->is_delete);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user',$this->create_user,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user',$this->update_user,true);
		$criteria->compare('award_remark',$this->award_remark,true);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(  
           		 'defaultOrder'=>'awardSms_id DESC',  
       		 ),  
       		'pagination'=>array(  
           		 'pageSize'=>20  
       		 ),  
		));
	}
	
	
		public function search2($event_id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('awardSms_id',$this->awardSms_id);
		$criteria->compare('event_id',$event_id);
		$criteria->compare('awardSms_title',$this->awardSms_title,true);
		$criteria->compare('message_en',$this->message_en,true);
		$criteria->compare('message_cn',$this->message_cn,true);
		$criteria->compare('is_delete',$this->is_delete);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user',$this->create_user,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user',$this->update_user,true);
		$criteria->compare('award_remark',$this->award_remark,true);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(  
           		 'defaultOrder'=>'awardSms_id DESC',  
       		 ),  
       		'pagination'=>array(  
           		 'pageSize'=>20  
       		 ),  
		));
	}
	//通过短信的id得到短信的标题
	public function getAwardSmsTitle($sms_id)
	{
		$model=EventAwardSms::model()->findByPk($sms_id);
		return $model->awardSms_title;
	}
	//通过event_id找到该活动下的短信模板
	public function getAwardSms($event_id){
		 $sql="select * from zy_event_award_sms where event_id =$event_id";
	 
	 	$rs =Yii::app()->db->createCommand($sql)->queryAll();
	 
	 	return CHtml::listData($rs,'awardSms_id','awardSms_title');
	}
}